package com.tianqu.tms.www.system.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.tianqu.tms.core.base.Logger;
import com.tianqu.tms.core.base.TmsAction;
import com.tianqu.tms.core.base.UserContext;
import com.tianqu.tms.core.util.TmsConstants;
import com.tianqu.tms.entity.Codes;
import com.tianqu.tms.www.system.actionform.AucBidTypeManageForm;
import com.tianqu.tms.www.system.controller.AucBidTypeCreationInputController;
import com.tianqu.tms.www.system.viewhelper.AucBidTypeManageViewHelper;

/**
 * @author zhangxueliang
 * 竞价模式添加入录
 */
public class AucBidTypeCreationInputAction extends TmsAction{

	private Logger logger = Logger.getLogger(AucBidTypeCreationInputAction.class);	
	@SuppressWarnings("unchecked")
	@Override
	protected ActionForward doAction(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response,
			UserContext uc) throws Exception {
		logger.debug(this.getClass().getName() + "#execute was called.");
		AucBidTypeCreationInputController controller = new AucBidTypeCreationInputController();
		controller.execute(uc);
		List aucTypeList = (List)uc.getAttribute(AucBidTypeCreationInputController.AUCTYPELIST);
		AucBidTypeManageViewHelper viewHelper = new AucBidTypeManageViewHelper();
		AucBidTypeManageViewHelper viewHelperOld = new AucBidTypeManageViewHelper();
		viewHelperOld = (AucBidTypeManageViewHelper)uc.getAttribute(TmsConstants.VIEWHELP);
		
		viewHelper.setAucTypeList(aucTypeList);
		//操作验证后页面返回值
		if(viewHelperOld != null){
			if(viewHelperOld.getTypeName() == null){
				AucBidTypeManageForm aucBidTypeManageForm = (AucBidTypeManageForm)form;
				viewHelperOld.setTypeName( aucBidTypeManageForm.getTypeName());
				viewHelperOld.setFareAmount(aucBidTypeManageForm.getFareAmount());
				viewHelperOld.setAuctionDeadline(aucBidTypeManageForm.getAuctionDeadline());
				viewHelperOld.setDelayTime(aucBidTypeManageForm.getDelayTime());
				viewHelperOld.setFirstExpetPrices(aucBidTypeManageForm.getFirstExpetPrices());
				
			}else{//确认页的上一步
				Codes codes = Codes.getInstance();
				viewHelperOld.setTypeName(String.valueOf(codes.getItemCodeByItemIdAndItemValue(Codes.AUCTION_TYPR, viewHelperOld.getTypeName())));
				viewHelperOld.setAucTypeList(aucTypeList);
			}			
			uc.setAttribute(TmsConstants.VIEWHELP, viewHelperOld);
			request.setAttribute("viewhelp", viewHelperOld);
		}else{
			uc.setAttribute(TmsConstants.VIEWHELP, viewHelper);
			request.setAttribute("viewhelp", viewHelper);
		}
		
		
		logger.debug(this.getClass().getName() + "#execute was completed.");
		return mapping.findForward(TmsConstants.SUCCESS);
	}

}
